package inspire13.duckhuntroid;

import android.util.FloatMath;

public class Vector2f 
{
	public float X;
	public float Y;
	
	public Vector2f()
	{
		X = 0.0f;
		Y = 0.0f;
	}
	
	public Vector2f(float x, float y)
	{
		X = x;
		Y = y;
	}
	
	/**
	 * Adds given vector and returns new one, doesn't modify existing vector 
	 */
	public Vector2f Add(Vector2f input)
	{
		Vector2f newVector = new Vector2f();
		newVector.X = X + input.X;
		newVector.Y = Y + input.Y;
		
		return newVector;
	}
	
	/**
	 * Subtracts given vector and returns new one, doesn't modify existing vector 
	 */
	public Vector2f Subtract(Vector2f input)
	{
		Vector2f newVector = new Vector2f();
		newVector.X = X - input.X;
		newVector.Y = Y - input.Y;
		
		return newVector;
	}
	
	/**
	 * Dot product with given vector
	 */
	public float Dot(Vector2f input)
	{
		return X*input.X + Y*input.Y;
	}
	
	/**
	 * Scales vector with the given amount and returns new one, doesn't modify existing vector
	 */
	public Vector2f Scale(float scale)
	{
		Vector2f newVector = new Vector2f();
		newVector.X = X * scale;
		newVector.Y = Y * scale;
		
		return newVector;
	}
	
	/**
	 * Returns length of vector
	 */
	public float Length()
	{
		return FloatMath.sqrt(X*X + Y*Y);
	}
	
	/**
	 * Returns squared length of vector
	 */
	public float SquaredLength()
	{
		return X*X + Y*Y;
	}
}
